{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## DAY4（数据框DataFrame列操作）\n",
    "\n",
    "- 取一列\n",
    "- 取多列\n",
    "- 构造新列\n",
    "- 插入新列\n",
    "- 移除列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2013-01-01  1.624345 -0.611756 -0.528172 -1.072969\n",
       "2013-01-02  0.865408 -2.301539  1.744812 -0.761207\n",
       "2013-01-03  0.319039 -0.249370  1.462108 -2.060141\n",
       "2013-01-04 -0.322417 -0.384054  1.133769 -1.099891\n",
       "2013-01-05 -0.172428 -0.877858  0.042214  0.582815\n",
       "2013-01-06 -1.100619  1.144724  0.901591  0.502494\n",
       "2013-01-07  0.900856 -0.683728 -0.122890 -0.935769\n",
       "2013-01-08 -0.267888  0.530355 -0.691661 -0.396754\n",
       "2013-01-09 -0.687173 -0.845206 -0.671246 -0.012665\n",
       "2013-01-10 -1.117310  0.234416  1.659802  0.742044"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 构造df\n",
    "np.random.seed(1)\n",
    "df = pd.DataFrame(np.random.randn(10,4), \n",
    "                  columns=list('ABCD'),\n",
    "                  index = pd.date_range('20130101', periods=10))\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 取一列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2013-01-01    1.624345\n",
       "2013-01-02    0.865408\n",
       "2013-01-03    0.319039\n",
       "2013-01-04   -0.322417\n",
       "2013-01-05   -0.172428\n",
       "2013-01-06   -1.100619\n",
       "2013-01-07    0.900856\n",
       "2013-01-08   -0.267888\n",
       "2013-01-09   -0.687173\n",
       "2013-01-10   -1.117310\n",
       "Freq: D, Name: A, dtype: float64"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2013-01-01    1.624345\n",
       "2013-01-02    0.865408\n",
       "2013-01-03    0.319039\n",
       "2013-01-04   -0.322417\n",
       "2013-01-05   -0.172428\n",
       "2013-01-06   -1.100619\n",
       "2013-01-07    0.900856\n",
       "2013-01-08   -0.267888\n",
       "2013-01-09   -0.687173\n",
       "2013-01-10   -1.117310\n",
       "Freq: D, Name: A, dtype: float64"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['A']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2013-01-01    1.624345\n",
       "2013-01-02    0.865408\n",
       "2013-01-03    0.319039\n",
       "2013-01-04   -0.322417\n",
       "2013-01-05   -0.172428\n",
       "2013-01-06   -1.100619\n",
       "2013-01-07    0.900856\n",
       "2013-01-08   -0.267888\n",
       "2013-01-09   -0.687173\n",
       "2013-01-10   -1.117310\n",
       "Freq: D, Name: A, dtype: float64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[:,'A']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2013-01-01    1.624345\n",
       "2013-01-02    0.865408\n",
       "2013-01-03    0.319039\n",
       "2013-01-04   -0.322417\n",
       "2013-01-05   -0.172428\n",
       "2013-01-06   -1.100619\n",
       "2013-01-07    0.900856\n",
       "2013-01-08   -0.267888\n",
       "2013-01-09   -0.687173\n",
       "2013-01-10   -1.117310\n",
       "Freq: D, Name: A, dtype: float64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[:,0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 取多列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B\n",
       "2013-01-01  1.624345 -0.611756\n",
       "2013-01-02  0.865408 -2.301539\n",
       "2013-01-03  0.319039 -0.249370\n",
       "2013-01-04 -0.322417 -0.384054\n",
       "2013-01-05 -0.172428 -0.877858\n",
       "2013-01-06 -1.100619  1.144724\n",
       "2013-01-07  0.900856 -0.683728\n",
       "2013-01-08 -0.267888  0.530355\n",
       "2013-01-09 -0.687173 -0.845206\n",
       "2013-01-10 -1.117310  0.234416"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['A','B']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         C         D\n",
       "2013-01-01  1.624345 -0.528172 -1.072969\n",
       "2013-01-02  0.865408  1.744812 -0.761207\n",
       "2013-01-03  0.319039  1.462108 -2.060141\n",
       "2013-01-04 -0.322417  1.133769 -1.099891\n",
       "2013-01-05 -0.172428  0.042214  0.582815\n",
       "2013-01-06 -1.100619  0.901591  0.502494\n",
       "2013-01-07  0.900856 -0.122890 -0.935769\n",
       "2013-01-08 -0.267888 -0.691661 -0.396754\n",
       "2013-01-09 -0.687173 -0.671246 -0.012665\n",
       "2013-01-10 -1.117310  1.659802  0.742044"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['A','C','D']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B\n",
       "2013-01-01  1.624345 -0.611756\n",
       "2013-01-02  0.865408 -2.301539\n",
       "2013-01-03  0.319039 -0.249370\n",
       "2013-01-04 -0.322417 -0.384054\n",
       "2013-01-05 -0.172428 -0.877858\n",
       "2013-01-06 -1.100619  1.144724\n",
       "2013-01-07  0.900856 -0.683728\n",
       "2013-01-08 -0.267888  0.530355\n",
       "2013-01-09 -0.687173 -0.845206\n",
       "2013-01-10 -1.117310  0.234416"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[:,['A','B']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B\n",
       "2013-01-01  1.624345 -0.611756\n",
       "2013-01-02  0.865408 -2.301539\n",
       "2013-01-03  0.319039 -0.249370\n",
       "2013-01-04 -0.322417 -0.384054\n",
       "2013-01-05 -0.172428 -0.877858\n",
       "2013-01-06 -1.100619  1.144724\n",
       "2013-01-07  0.900856 -0.683728\n",
       "2013-01-08 -0.267888  0.530355\n",
       "2013-01-09 -0.687173 -0.845206\n",
       "2013-01-10 -1.117310  0.234416"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[:,[0,1]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   B         C         D\n",
       "2013-01-01 -0.611756 -0.528172 -1.072969\n",
       "2013-01-02 -2.301539  1.744812 -0.761207\n",
       "2013-01-03 -0.249370  1.462108 -2.060141\n",
       "2013-01-04 -0.384054  1.133769 -1.099891\n",
       "2013-01-05 -0.877858  0.042214  0.582815\n",
       "2013-01-06  1.144724  0.901591  0.502494\n",
       "2013-01-07 -0.683728 -0.122890 -0.935769\n",
       "2013-01-08  0.530355 -0.691661 -0.396754\n",
       "2013-01-09 -0.845206 -0.671246 -0.012665\n",
       "2013-01-10  0.234416  1.659802  0.742044"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[:,'B':'D']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>D</th>\n",
       "      <th>C</th>\n",
       "      <th>B</th>\n",
       "      <th>A</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>-1.072969</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>1.624345</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>-0.761207</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>0.865408</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>-2.060141</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>0.319039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-1.099891</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>-0.322417</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>0.582815</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>-0.172428</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>0.502494</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>-1.100619</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>-0.935769</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>0.900856</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.396754</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.267888</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.012665</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.687173</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>0.742044</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>-1.117310</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   D         C         B         A\n",
       "2013-01-01 -1.072969 -0.528172 -0.611756  1.624345\n",
       "2013-01-02 -0.761207  1.744812 -2.301539  0.865408\n",
       "2013-01-03 -2.060141  1.462108 -0.249370  0.319039\n",
       "2013-01-04 -1.099891  1.133769 -0.384054 -0.322417\n",
       "2013-01-05  0.582815  0.042214 -0.877858 -0.172428\n",
       "2013-01-06  0.502494  0.901591  1.144724 -1.100619\n",
       "2013-01-07 -0.935769 -0.122890 -0.683728  0.900856\n",
       "2013-01-08 -0.396754 -0.691661  0.530355 -0.267888\n",
       "2013-01-09 -0.012665 -0.671246 -0.845206 -0.687173\n",
       "2013-01-10  0.742044  1.659802  0.234416 -1.117310"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_index(axis=1,ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>D</th>\n",
       "      <th>C</th>\n",
       "      <th>B</th>\n",
       "      <th>A</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>-1.072969</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>1.624345</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>-0.761207</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>0.865408</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>-2.060141</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>0.319039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-1.099891</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>-0.322417</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>0.582815</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>-0.172428</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>0.502494</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>-1.100619</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>-0.935769</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>0.900856</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.396754</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.267888</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.012665</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.687173</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>0.742044</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>-1.117310</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   D         C         B         A\n",
       "2013-01-01 -1.072969 -0.528172 -0.611756  1.624345\n",
       "2013-01-02 -0.761207  1.744812 -2.301539  0.865408\n",
       "2013-01-03 -2.060141  1.462108 -0.249370  0.319039\n",
       "2013-01-04 -1.099891  1.133769 -0.384054 -0.322417\n",
       "2013-01-05  0.582815  0.042214 -0.877858 -0.172428\n",
       "2013-01-06  0.502494  0.901591  1.144724 -1.100619\n",
       "2013-01-07 -0.935769 -0.122890 -0.683728  0.900856\n",
       "2013-01-08 -0.396754 -0.691661  0.530355 -0.267888\n",
       "2013-01-09 -0.012665 -0.671246 -0.845206 -0.687173\n",
       "2013-01-10  0.742044  1.659802  0.234416 -1.117310"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[:,::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   B         C         D\n",
       "2013-01-01 -0.611756 -0.528172 -1.072969\n",
       "2013-01-02 -2.301539  1.744812 -0.761207\n",
       "2013-01-03 -0.249370  1.462108 -2.060141\n",
       "2013-01-04 -0.384054  1.133769 -1.099891\n",
       "2013-01-05 -0.877858  0.042214  0.582815\n",
       "2013-01-06  1.144724  0.901591  0.502494\n",
       "2013-01-07 -0.683728 -0.122890 -0.935769\n",
       "2013-01-08  0.530355 -0.691661 -0.396754\n",
       "2013-01-09 -0.845206 -0.671246 -0.012665\n",
       "2013-01-10  0.234416  1.659802  0.742044"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[:,1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C\n",
       "2013-01-01  1.624345 -0.611756 -0.528172\n",
       "2013-01-02  0.865408 -2.301539  1.744812\n",
       "2013-01-03  0.319039 -0.249370  1.462108\n",
       "2013-01-04 -0.322417 -0.384054  1.133769\n",
       "2013-01-05 -0.172428 -0.877858  0.042214\n",
       "2013-01-06 -1.100619  1.144724  0.901591\n",
       "2013-01-07  0.900856 -0.683728 -0.122890\n",
       "2013-01-08 -0.267888  0.530355 -0.691661\n",
       "2013-01-09 -0.687173 -0.845206 -0.671246\n",
       "2013-01-10 -1.117310  0.234416  1.659802"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.reindex(columns =list('ABC'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 构造新列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2013-01-01  1.624345 -0.611756 -0.528172 -1.072969\n",
       "2013-01-02  0.865408 -2.301539  1.744812 -0.761207\n",
       "2013-01-03  0.319039 -0.249370  1.462108 -2.060141\n",
       "2013-01-04 -0.322417 -0.384054  1.133769 -1.099891\n",
       "2013-01-05 -0.172428 -0.877858  0.042214  0.582815\n",
       "2013-01-06 -1.100619  1.144724  0.901591  0.502494\n",
       "2013-01-07  0.900856 -0.683728 -0.122890 -0.935769\n",
       "2013-01-08 -0.267888  0.530355 -0.691661 -0.396754\n",
       "2013-01-09 -0.687173 -0.845206 -0.671246 -0.012665\n",
       "2013-01-10 -1.117310  0.234416  1.659802  0.742044"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['E'] = df['A']+df['B']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2013-01-01    1.012589\n",
       "2013-01-02   -1.436131\n",
       "2013-01-03    0.069669\n",
       "2013-01-04   -0.706472\n",
       "2013-01-05   -1.050287\n",
       "2013-01-06    0.044105\n",
       "2013-01-07    0.217128\n",
       "2013-01-08    0.262467\n",
       "2013-01-09   -1.532378\n",
       "2013-01-10   -0.882895\n",
       "Freq: D, Name: E, dtype: float64"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['E']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 插入新列\n",
    "\n",
    "- assign\n",
    "- insert\n",
    "- reindex\n",
    "- concat\n",
    "- loc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "df1 = df.copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "      <th>new1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "      <td>1.012589</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "      <td>-1.436131</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "      <td>0.069669</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "      <td>-0.706472</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "      <td>-1.050287</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "      <td>0.044105</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "      <td>0.217128</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "      <td>0.262467</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "      <td>-1.532378</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "      <td>-0.882895</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D         E  new1\n",
       "2013-01-01  1.624345 -0.611756 -0.528172 -1.072969  1.012589     1\n",
       "2013-01-02  0.865408 -2.301539  1.744812 -0.761207 -1.436131     2\n",
       "2013-01-03  0.319039 -0.249370  1.462108 -2.060141  0.069669     3\n",
       "2013-01-04 -0.322417 -0.384054  1.133769 -1.099891 -0.706472     4\n",
       "2013-01-05 -0.172428 -0.877858  0.042214  0.582815 -1.050287     5\n",
       "2013-01-06 -1.100619  1.144724  0.901591  0.502494  0.044105     6\n",
       "2013-01-07  0.900856 -0.683728 -0.122890 -0.935769  0.217128     7\n",
       "2013-01-08 -0.267888  0.530355 -0.691661 -0.396754  0.262467     8\n",
       "2013-01-09 -0.687173 -0.845206 -0.671246 -0.012665 -1.532378     9\n",
       "2013-01-10 -1.117310  0.234416  1.659802  0.742044 -0.882895    10"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.assign(new1 = [1,2,3,4,5,6,7,8,9,10])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "      <th>new1</th>\n",
       "      <th>new2</th>\n",
       "      <th>new3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "      <td>1.012589</td>\n",
       "      <td>15.631697</td>\n",
       "      <td>31.263394</td>\n",
       "      <td>1250.535778</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "      <td>-1.436131</td>\n",
       "      <td>6.352538</td>\n",
       "      <td>12.705075</td>\n",
       "      <td>508.203008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "      <td>0.069669</td>\n",
       "      <td>2.941021</td>\n",
       "      <td>5.882041</td>\n",
       "      <td>235.281647</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "      <td>-0.706472</td>\n",
       "      <td>-3.608226</td>\n",
       "      <td>-7.216453</td>\n",
       "      <td>-288.658112</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "      <td>-1.050287</td>\n",
       "      <td>-2.602140</td>\n",
       "      <td>-5.204281</td>\n",
       "      <td>-208.171239</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "      <td>0.044105</td>\n",
       "      <td>-9.861468</td>\n",
       "      <td>-19.722936</td>\n",
       "      <td>-788.917445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "      <td>0.217128</td>\n",
       "      <td>8.324832</td>\n",
       "      <td>16.649663</td>\n",
       "      <td>665.986531</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "      <td>0.262467</td>\n",
       "      <td>-2.148525</td>\n",
       "      <td>-4.297051</td>\n",
       "      <td>-171.882026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "      <td>-1.532378</td>\n",
       "      <td>-7.716933</td>\n",
       "      <td>-15.433865</td>\n",
       "      <td>-617.354611</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "      <td>-0.882895</td>\n",
       "      <td>-10.938688</td>\n",
       "      <td>-21.877376</td>\n",
       "      <td>-875.095023</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D         E       new1  \\\n",
       "2013-01-01  1.624345 -0.611756 -0.528172 -1.072969  1.012589  15.631697   \n",
       "2013-01-02  0.865408 -2.301539  1.744812 -0.761207 -1.436131   6.352538   \n",
       "2013-01-03  0.319039 -0.249370  1.462108 -2.060141  0.069669   2.941021   \n",
       "2013-01-04 -0.322417 -0.384054  1.133769 -1.099891 -0.706472  -3.608226   \n",
       "2013-01-05 -0.172428 -0.877858  0.042214  0.582815 -1.050287  -2.602140   \n",
       "2013-01-06 -1.100619  1.144724  0.901591  0.502494  0.044105  -9.861468   \n",
       "2013-01-07  0.900856 -0.683728 -0.122890 -0.935769  0.217128   8.324832   \n",
       "2013-01-08 -0.267888  0.530355 -0.691661 -0.396754  0.262467  -2.148525   \n",
       "2013-01-09 -0.687173 -0.845206 -0.671246 -0.012665 -1.532378  -7.716933   \n",
       "2013-01-10 -1.117310  0.234416  1.659802  0.742044 -0.882895 -10.938688   \n",
       "\n",
       "                 new2         new3  \n",
       "2013-01-01  31.263394  1250.535778  \n",
       "2013-01-02  12.705075   508.203008  \n",
       "2013-01-03   5.882041   235.281647  \n",
       "2013-01-04  -7.216453  -288.658112  \n",
       "2013-01-05  -5.204281  -208.171239  \n",
       "2013-01-06 -19.722936  -788.917445  \n",
       "2013-01-07  16.649663   665.986531  \n",
       "2013-01-08  -4.297051  -171.882026  \n",
       "2013-01-09 -15.433865  -617.354611  \n",
       "2013-01-10 -21.877376  -875.095023  "
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.assign(new1 = lambda df: df.A*10+df.B, \n",
    "           new2 = lambda x: x.new1*2,\n",
    "           new3 = lambda x: x.new1*100-x.new2*10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "      <td>1.012589</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "      <td>-1.436131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "      <td>0.069669</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "      <td>-0.706472</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "      <td>-1.050287</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "      <td>0.044105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "      <td>0.217128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "      <td>0.262467</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "      <td>-1.532378</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "      <td>-0.882895</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D         E\n",
       "2013-01-01  1.624345 -0.611756 -0.528172 -1.072969  1.012589\n",
       "2013-01-02  0.865408 -2.301539  1.744812 -0.761207 -1.436131\n",
       "2013-01-03  0.319039 -0.249370  1.462108 -2.060141  0.069669\n",
       "2013-01-04 -0.322417 -0.384054  1.133769 -1.099891 -0.706472\n",
       "2013-01-05 -0.172428 -0.877858  0.042214  0.582815 -1.050287\n",
       "2013-01-06 -1.100619  1.144724  0.901591  0.502494  0.044105\n",
       "2013-01-07  0.900856 -0.683728 -0.122890 -0.935769  0.217128\n",
       "2013-01-08 -0.267888  0.530355 -0.691661 -0.396754  0.262467\n",
       "2013-01-09 -0.687173 -0.845206 -0.671246 -0.012665 -1.532378\n",
       "2013-01-10 -1.117310  0.234416  1.659802  0.742044 -0.882895"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1\n",
    "# 并无改变"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dataframe after adding new column using 【assign】:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "      <td>1.012589</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "      <td>-1.436131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "      <td>0.069669</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "      <td>-0.706472</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "      <td>-1.050287</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "      <td>0.044105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "      <td>0.217128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "      <td>0.262467</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "      <td>-1.532378</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "      <td>-0.882895</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D         E\n",
       "2013-01-01  1.624345 -0.611756 -0.528172 -1.072969  1.012589\n",
       "2013-01-02  0.865408 -2.301539  1.744812 -0.761207 -1.436131\n",
       "2013-01-03  0.319039 -0.249370  1.462108 -2.060141  0.069669\n",
       "2013-01-04 -0.322417 -0.384054  1.133769 -1.099891 -0.706472\n",
       "2013-01-05 -0.172428 -0.877858  0.042214  0.582815 -1.050287\n",
       "2013-01-06 -1.100619  1.144724  0.901591  0.502494  0.044105\n",
       "2013-01-07  0.900856 -0.683728 -0.122890 -0.935769  0.217128\n",
       "2013-01-08 -0.267888  0.530355 -0.691661 -0.396754  0.262467\n",
       "2013-01-09 -0.687173 -0.845206 -0.671246 -0.012665 -1.532378\n",
       "2013-01-10 -1.117310  0.234416  1.659802  0.742044 -0.882895"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = df.copy()\n",
    "\n",
    "# assign\n",
    "df1.assign(new1 = [1,2,3,4,5,6,7,8,9,10])\n",
    "\n",
    "print(\"Dataframe after adding new column using 【assign】:\")\n",
    "\n",
    "df1\n",
    "\n",
    "# df1没变化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# df1.insert(3,'E',3, allow_duplicates = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dataframe after adding new column using 【insert】 at a particular position:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>new2</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "      <td>1.012589</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>2</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "      <td>-1.436131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>3</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "      <td>0.069669</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>4</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "      <td>-0.706472</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>5</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "      <td>-1.050287</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>6</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "      <td>0.044105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>7</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "      <td>0.217128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>8</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "      <td>0.262467</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>9</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "      <td>-1.532378</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>10</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "      <td>-0.882895</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A  new2         B         C         D         E\n",
       "2013-01-01  1.624345     1 -0.611756 -0.528172 -1.072969  1.012589\n",
       "2013-01-02  0.865408     2 -2.301539  1.744812 -0.761207 -1.436131\n",
       "2013-01-03  0.319039     3 -0.249370  1.462108 -2.060141  0.069669\n",
       "2013-01-04 -0.322417     4 -0.384054  1.133769 -1.099891 -0.706472\n",
       "2013-01-05 -0.172428     5 -0.877858  0.042214  0.582815 -1.050287\n",
       "2013-01-06 -1.100619     6  1.144724  0.901591  0.502494  0.044105\n",
       "2013-01-07  0.900856     7 -0.683728 -0.122890 -0.935769  0.217128\n",
       "2013-01-08 -0.267888     8  0.530355 -0.691661 -0.396754  0.262467\n",
       "2013-01-09 -0.687173     9 -0.845206 -0.671246 -0.012665 -1.532378\n",
       "2013-01-10 -1.117310    10  0.234416  1.659802  0.742044 -0.882895"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = df.copy()\n",
    "\n",
    "\n",
    "df1.insert(1, \"new2\", [1,2,3,4,5,6,7,8,9,10])\n",
    "\n",
    "print(\"Dataframe after adding new column using 【insert】 at a particular position:\")\n",
    "\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "      <th>F</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "      <td>1.012589</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "      <td>-1.436131</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "      <td>0.069669</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "      <td>-0.706472</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "      <td>-1.050287</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "      <td>0.044105</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "      <td>0.217128</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "      <td>0.262467</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "      <td>-1.532378</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "      <td>-0.882895</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D         E  F\n",
       "2013-01-01  1.624345 -0.611756 -0.528172 -1.072969  1.012589  0\n",
       "2013-01-02  0.865408 -2.301539  1.744812 -0.761207 -1.436131  0\n",
       "2013-01-03  0.319039 -0.249370  1.462108 -2.060141  0.069669  0\n",
       "2013-01-04 -0.322417 -0.384054  1.133769 -1.099891 -0.706472  0\n",
       "2013-01-05 -0.172428 -0.877858  0.042214  0.582815 -1.050287  0\n",
       "2013-01-06 -1.100619  1.144724  0.901591  0.502494  0.044105  0\n",
       "2013-01-07  0.900856 -0.683728 -0.122890 -0.935769  0.217128  0\n",
       "2013-01-08 -0.267888  0.530355 -0.691661 -0.396754  0.262467  0\n",
       "2013-01-09 -0.687173 -0.845206 -0.671246 -0.012665 -1.532378  0\n",
       "2013-01-10 -1.117310  0.234416  1.659802  0.742044 -0.882895  0"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.reindex(columns = list('ABCDEF'), fill_value = 0)\n",
    "# 填充固定值\n",
    "# 列名过多不适合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "      <th>F</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "      <td>1.012589</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "      <td>-1.436131</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "      <td>0.069669</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "      <td>-0.706472</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "      <td>-1.050287</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "      <td>0.044105</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "      <td>0.217128</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "      <td>0.262467</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "      <td>-1.532378</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "      <td>-0.882895</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D         E  F\n",
       "2013-01-01  1.624345 -0.611756 -0.528172 -1.072969  1.012589  0\n",
       "2013-01-02  0.865408 -2.301539  1.744812 -0.761207 -1.436131  1\n",
       "2013-01-03  0.319039 -0.249370  1.462108 -2.060141  0.069669  2\n",
       "2013-01-04 -0.322417 -0.384054  1.133769 -1.099891 -0.706472  3\n",
       "2013-01-05 -0.172428 -0.877858  0.042214  0.582815 -1.050287  4\n",
       "2013-01-06 -1.100619  1.144724  0.901591  0.502494  0.044105  5\n",
       "2013-01-07  0.900856 -0.683728 -0.122890 -0.935769  0.217128  6\n",
       "2013-01-08 -0.267888  0.530355 -0.691661 -0.396754  0.262467  7\n",
       "2013-01-09 -0.687173 -0.845206 -0.671246 -0.012665 -1.532378  8\n",
       "2013-01-10 -1.117310  0.234416  1.659802  0.742044 -0.882895  9"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df,\n",
    "        pd.Series([x for x in range(len(df))], index = df.index, name = 'F')], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.loc[:,'F'] = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "      <th>F</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "      <td>1.012589</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "      <td>-1.436131</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "      <td>0.069669</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "      <td>-0.706472</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "      <td>-1.050287</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "      <td>0.044105</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "      <td>0.217128</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "      <td>0.262467</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "      <td>-1.532378</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "      <td>-0.882895</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D         E   F\n",
       "2013-01-01  1.624345 -0.611756 -0.528172 -1.072969  1.012589  10\n",
       "2013-01-02  0.865408 -2.301539  1.744812 -0.761207 -1.436131  10\n",
       "2013-01-03  0.319039 -0.249370  1.462108 -2.060141  0.069669  10\n",
       "2013-01-04 -0.322417 -0.384054  1.133769 -1.099891 -0.706472  10\n",
       "2013-01-05 -0.172428 -0.877858  0.042214  0.582815 -1.050287  10\n",
       "2013-01-06 -1.100619  1.144724  0.901591  0.502494  0.044105  10\n",
       "2013-01-07  0.900856 -0.683728 -0.122890 -0.935769  0.217128  10\n",
       "2013-01-08 -0.267888  0.530355 -0.691661 -0.396754  0.262467  10\n",
       "2013-01-09 -0.687173 -0.845206 -0.671246 -0.012665 -1.532378  10\n",
       "2013-01-10 -1.117310  0.234416  1.659802  0.742044 -0.882895  10"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "      <th>F</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "      <td>1.012589</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "      <td>-1.436131</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "      <td>0.069669</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "      <td>-0.706472</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "      <td>-1.050287</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "      <td>0.044105</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "      <td>0.217128</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "      <td>0.262467</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "      <td>-1.532378</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "      <td>-0.882895</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D         E   F\n",
       "2013-01-01  1.624345 -0.611756 -0.528172 -1.072969  1.012589  10\n",
       "2013-01-02  0.865408 -2.301539  1.744812 -0.761207 -1.436131  10\n",
       "2013-01-03  0.319039 -0.249370  1.462108 -2.060141  0.069669  10\n",
       "2013-01-04 -0.322417 -0.384054  1.133769 -1.099891 -0.706472  10\n",
       "2013-01-05 -0.172428 -0.877858  0.042214  0.582815 -1.050287  10\n",
       "2013-01-06 -1.100619  1.144724  0.901591  0.502494  0.044105  10\n",
       "2013-01-07  0.900856 -0.683728 -0.122890 -0.935769  0.217128  10\n",
       "2013-01-08 -0.267888  0.530355 -0.691661 -0.396754  0.262467  10\n",
       "2013-01-09 -0.687173 -0.845206 -0.671246 -0.012665 -1.532378  10\n",
       "2013-01-10 -1.117310  0.234416  1.659802  0.742044 -0.882895  10"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 移除列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>F</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D   F\n",
       "2013-01-01  1.624345 -0.611756 -0.528172 -1.072969  10\n",
       "2013-01-02  0.865408 -2.301539  1.744812 -0.761207  10\n",
       "2013-01-03  0.319039 -0.249370  1.462108 -2.060141  10\n",
       "2013-01-04 -0.322417 -0.384054  1.133769 -1.099891  10\n",
       "2013-01-05 -0.172428 -0.877858  0.042214  0.582815  10\n",
       "2013-01-06 -1.100619  1.144724  0.901591  0.502494  10\n",
       "2013-01-07  0.900856 -0.683728 -0.122890 -0.935769  10\n",
       "2013-01-08 -0.267888  0.530355 -0.691661 -0.396754  10\n",
       "2013-01-09 -0.687173 -0.845206 -0.671246 -0.012665  10\n",
       "2013-01-10 -1.117310  0.234416  1.659802  0.742044  10"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.drop('E',axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2013-01-01  1.624345 -0.611756 -0.528172 -1.072969\n",
       "2013-01-02  0.865408 -2.301539  1.744812 -0.761207\n",
       "2013-01-03  0.319039 -0.249370  1.462108 -2.060141\n",
       "2013-01-04 -0.322417 -0.384054  1.133769 -1.099891\n",
       "2013-01-05 -0.172428 -0.877858  0.042214  0.582815\n",
       "2013-01-06 -1.100619  1.144724  0.901591  0.502494\n",
       "2013-01-07  0.900856 -0.683728 -0.122890 -0.935769\n",
       "2013-01-08 -0.267888  0.530355 -0.691661 -0.396754\n",
       "2013-01-09 -0.687173 -0.845206 -0.671246 -0.012665\n",
       "2013-01-10 -1.117310  0.234416  1.659802  0.742044"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.drop(['E','F'],axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.drop(['E','F'],axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>1.624345</td>\n",
       "      <td>-0.611756</td>\n",
       "      <td>-0.528172</td>\n",
       "      <td>-1.072969</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>0.865408</td>\n",
       "      <td>-2.301539</td>\n",
       "      <td>1.744812</td>\n",
       "      <td>-0.761207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>0.319039</td>\n",
       "      <td>-0.249370</td>\n",
       "      <td>1.462108</td>\n",
       "      <td>-2.060141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-04</th>\n",
       "      <td>-0.322417</td>\n",
       "      <td>-0.384054</td>\n",
       "      <td>1.133769</td>\n",
       "      <td>-1.099891</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-05</th>\n",
       "      <td>-0.172428</td>\n",
       "      <td>-0.877858</td>\n",
       "      <td>0.042214</td>\n",
       "      <td>0.582815</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-06</th>\n",
       "      <td>-1.100619</td>\n",
       "      <td>1.144724</td>\n",
       "      <td>0.901591</td>\n",
       "      <td>0.502494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-07</th>\n",
       "      <td>0.900856</td>\n",
       "      <td>-0.683728</td>\n",
       "      <td>-0.122890</td>\n",
       "      <td>-0.935769</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-08</th>\n",
       "      <td>-0.267888</td>\n",
       "      <td>0.530355</td>\n",
       "      <td>-0.691661</td>\n",
       "      <td>-0.396754</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-09</th>\n",
       "      <td>-0.687173</td>\n",
       "      <td>-0.845206</td>\n",
       "      <td>-0.671246</td>\n",
       "      <td>-0.012665</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-10</th>\n",
       "      <td>-1.117310</td>\n",
       "      <td>0.234416</td>\n",
       "      <td>1.659802</td>\n",
       "      <td>0.742044</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2013-01-01  1.624345 -0.611756 -0.528172 -1.072969\n",
       "2013-01-02  0.865408 -2.301539  1.744812 -0.761207\n",
       "2013-01-03  0.319039 -0.249370  1.462108 -2.060141\n",
       "2013-01-04 -0.322417 -0.384054  1.133769 -1.099891\n",
       "2013-01-05 -0.172428 -0.877858  0.042214  0.582815\n",
       "2013-01-06 -1.100619  1.144724  0.901591  0.502494\n",
       "2013-01-07  0.900856 -0.683728 -0.122890 -0.935769\n",
       "2013-01-08 -0.267888  0.530355 -0.691661 -0.396754\n",
       "2013-01-09 -0.687173 -0.845206 -0.671246 -0.012665\n",
       "2013-01-10 -1.117310  0.234416  1.659802  0.742044"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
